#include "Core.h"
#include "Generic\IniFile.h"
#include "Generic\GameTime.h"
#include "Define.h"
#include "Generic\Convert.h"
#include "Debug\DebugLog.h"
#include "Entity\SBackground.h"
#include "Managers\RenderManager.h"
#include "Managers\PhysicsManager.h"
#include "Managers\StateManager.h"
#include "States\MenuState.h"
#include "States\PlayState.h"
#include "Generic\SFMLGameTime.h"
#include "Generic\MessageSystem.h"
#include "Managers\InputManager.h"
#include "Managers\ResourceManager.h"
#include "Generic\Random.h"

#ifdef _WIN32
#include "Engines\SFML2DRenderEngine.h"
#include "Engines\SFMLAudioEngine.h"
#include "SFML\Graphics.hpp"
#endif

Core::Core(void){}
Core::~Core(void){}

bool Core::initialize()
{
	Debug::setLogFile(".\\logs\\log", "txt", true);
	vn::Random::initialize();
#ifdef _WIN32
	RenderManager::getSingleton().createRenderEngine(new SFML2DRenderEngine(3));
	ResourceManager::getSingleton().createAudioEngine(new SFMLAudioEngine);
	InputManager::getSingleton().addKeyFunction("ok", (void*)sf::Keyboard::Return);
	InputManager::getSingleton().addKeyFunction("cancel", (void*)sf::Keyboard::LControl);
	InputManager::getSingleton().addKeyFunction("jump", (void*)sf::Keyboard::Space);
	InputManager::getSingleton().addKeyFunction("left", (void*)sf::Keyboard::Left);
	InputManager::getSingleton().addKeyFunction("right", (void*)sf::Keyboard::Right);
	InputManager::getSingleton().addKeyFunction("up", (void*)sf::Keyboard::Up);
	InputManager::getSingleton().addKeyFunction("down", (void*)sf::Keyboard::Down);
	InputManager::getSingleton().addKeyFunction("shoot", (void*)sf::Keyboard::X);
	InputManager::getSingleton().addKeyFunction("pause", (void*)sf::Keyboard::Escape);
#endif

	//EXAMPLE (wishful thinking)
	/*
#ifdef _ANDROID
	RenderManager::getSingleton().createRenderEngine(new OpenGLESRenderEngine(3));
#endif
	*/
	StateManager::getSingleton().setState(new MenuState);
	return true;
}

void Core::run()
{
	StateManager::getSingleton().start();
}

void Core::shutdown()
{
	StateManager::clean();
	PhysicsManager::clean();
	RenderManager::clean();
	ResourceManager::clean();
	MessageSystem::clean();
	InputManager::clean();
}
